<?php

###########################
# Ampache Mass Import M3U #
###########################
# Author:
# ------
# Sam Dekeyser
# 
# Usage:
# ------
# change the settings below to match your configuration
#
# run the file:
#   php mass_m3u.php
#
#########################
#
# Functions based upon usage in playlist.php
# import_m3u is defined in catalog.class.php
#
# MIT License
#

define('NO_SESSION','1');

require_once 'lib/init.php';

###
# Settings
# Important: don't forget a trailing slash with directories!
###
$m3u_dir = "path to M3U directory";
# end of settings

ob_implicit_flush(true);
ob_end_flush();

# Make list of all M3U files in directory
$files = glob($m3u_dir . "*.m3u");

print count($files) . " M3U-files found.\n";
flush();

# Process file per file
foreach($files as $m3u) 
{
	$playlist = new Catalog();
	$result 	= $playlist->import_m3u($m3u);
	
	if($result == false) 
	{
		print "[ERROR] - Could not import " . $m3u . "\n" . $reason . "\n";
	}
	else
	{
		print "[OK] - " . basename($m3u, ".m3u") . "\n"; 
	}
	flush();
}

print "Finished.\n"

?>